package com.shiro.service;

import com.shiro.dao.PrimissionDao;
import com.shiro.dao.RoleDao;
import com.shiro.dao.RolePermissionDao;
import com.shiro.domain.Primission;
import com.shiro.domain.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.beans.Transient;
import java.util.List;

@Service
public class RolePrimissionService {
    @Autowired
    PrimissionDao primissionDao;
    @Autowired
    RoleDao roleDao;
    @Autowired
    RolePermissionDao rolePermissionDao;

    @Transient
    public void  add(int roleId,int primissionId){
       List<Primission> list = primissionDao.selectPrimissionById(primissionId);
        int j = 0;
            for (int i = rolePermissionDao.selectRolePermissionId(); (i - rolePermissionDao.selectRolePermissionId()) < list.size(); i++) {
                Primission primission = list.get(j);
                primission.getId();
                rolePermissionDao.insertRolePermission(i, roleId, primission.getId());
                j++;
            }
    }
    public Role select(String name ){
        return roleDao.findRoleByName(name);
    }
}
